<?php
/**
 * IndexController
 * @author ComsenInc     
 * @copyright  Copyright (c)2007
 * @license
 */
class ViewController extends Zend_Controller_Action {

	function init(){
        $this->db = Zend_Registry::get('db');
        $this->smarty = Zend_Registry::get('smarty');
        $this->cache =Zend_Registry::get('cache');
        Zend_Loader::loadClass('Forums');
        Zend_Loader::loadClass('Posts');
        /* 验证用户是否已经登陆*/
        $this->smarty->assign('user',(array)Zend_Auth::getInstance()->getIdentity());
        $this->smarty->assign('IMGDIR',$this->_request->getBaseUrl().'/'.$this->smarty->template_dir);
 
    }

	function indexAction(){
		$this->_redirect('/');
	    
	}
   function threadAction(){
	     $this->tid =(int)$this ->_getParam('tid');
	     if($this->tid == 0) { 
         	$this->_redirect('/');
         }
         $this->paper = (int)$this->_getParam('paper');
         if($this->paper == 0) { 
         	$this->paper = 1; 
         }
         
         $posts = new Posts();
         $this->smarty->assign('first',$posts ->get_first_post($this->tid));
         $replies_posts = $posts ->get_replies_posts($this->paper,$this->tid,10,'/view/thread/tid/'.$this->_getParam('tid').'/paper/');
	     $this->smarty->assign('replies_posts',$replies_posts);
         $this->smarty->assign('pagurl',$posts->pagurl);
         $this->smarty->display('viewthread.tpl');
         var_dump($replies_posts);
 
	}
   
	
	public function __call($method, $args)    
    {        
        if ('Action' == substr($method, -6)) 
        {            
            // If the action method was not found, forward to the index action
            //如果action方法没有找到,则转向到index action           
            return $this->_forward('index');        
        }        
        // all other methods throw an exception 
        //所有其他的方法则扔出一个错误信息  
        throw new Exception('Invalid method "' . $method . '" called');    
    }
    
    public function noRouterAction()
    {
        $this->_redirect('/');
    }
    
}